<template>
	<view class="myblog" style="background-color: rgb(245, 245, 245);height: 100vh;">
		<navBar title="我赞过的" ></navBar>
		
		<view class="kong_img" v-show="false">
			<image src="../../static/kong.jpeg"></image>
		</view>
		
		<view class="content">
			<view class="content-item"  v-for="(item,index) in praiseList" :key="item.blogId" @click="toDlogdesc(item)">
				<view class="content-item-left">
					<image class="left-img" :src="item.blog.cover" alt=""></image> 
				</view>
		
				<view class="content-item-right">
					<view class="item_top_text">{{item.blog.title}}</view>
					<view class="item_top_lei">
						<text class="top_lei">{{item.blog.BlogClassifies[0].classifyName}}
						</text>
					</view>
					<view class="item_middle_box">
						<view class="item_middle_item">
							<image src="/static/dianzan.png" mode=""></image>
							<text>{{item.blog.like_count}}</text>
						</view>
						<view class="item_middle_item">
							<image src="/static/评论 (1).png" mode=""></image>
							<text>{{item.blog.comment_count}}</text>
						</view>
						<view class="item_middle_item">
							<image src="/static/浏览 (1).png" mode=""></image>
							<text>{{item.blog.read_count}}</text>
						</view>
					</view>
					<view class="item-bottom">{{formateDate(item.blog.createdAt)}}&nbsp;发布</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	export default {
		data() {
			return {
				praiseList:[]
			}
		},
		onLoad() {
			this.praise()
		},
		onShow() {
			this.praise()
		},
		methods: {
			 praise(){
				uni.request({
					url: 'https://eggblog.bluej.cn/api/user/getLikeBlog', //获取点赞博客
					header: {
						"x-token": this.userInfo.token //自定义请求头信息
					},
					success: (res) => {
						console.log(res);
						this.praiseList = res.data.data.rows
					}
				})
			},
			addZero(num) {
				return num < 10 ? '0' + num : num;
			},
			formateDate(date) {
				const arr = date.split('T');
				const d = arr[0];
				const darr = d.split('-');
			
				const t = arr[1];
				const tarr = t.split('.000');
				const marr = tarr[0].split(':');
			
				const dd =
					parseInt(darr[0]) +
					'年' +
					parseInt(darr[1]) +
					'月' +
					parseInt(darr[2]) +
					'日' + ' ' +
					this.addZero(parseInt(marr[0]) + 8) +
					'时' +
					this.addZero(parseInt(marr[1])) +
					'分'
				return dd;
			},
			toDlogdesc(item) {
				uni.navigateTo({
					url: '/subpages/blogdesc/blogdesc?id=' + item.blogId,
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			}
		},

		computed: {
			...mapState(['userInfo'])
		},
	}
</script>

<style lang="scss">
.myblog {
		.kong_img {
			width: 320px;
			height: 240px;
			margin: 80px auto;
		}

		.content {
			box-sizing: border-box;
			padding: 15px 15px 0 15px;
			background-color: rgb(245, 245, 245);

			.content-item {
				box-sizing: border-box;
				padding: 12px;
				display: flex;
				background-color: #fff;
				width: 345px;
				height: 124px;
				justify-content: space-between;
				border-radius: 5px;
				margin-bottom: 24px;
				box-shadow: rgba(0, 0, 0, 0.35) 0px 5px 15px;

				.content-item-left {
					width: 100px;
					height: 100px;

					.left-img {
						width: 100px;
						height: 100px;
						box-shadow: rgba(149, 157, 165, 0.2) 0px 8px 24px;
					}
				}

				.content-item-right {
					width: 200px;
					height: 100px;
					display: flex;
					flex-direction: column;
					justify-content: space-between;

					.item_top_text {
						font-size: 16px;
						font-weight: bold;
						width: 200px;
						white-space: nowrap;
						overflow: hidden;
						text-overflow: ellipsis;
					}

					.item_top_lei {
						width: fit-content;
						border: none;
						border-radius: 16px;
						box-shadow: none;
						font-weight: 600;
						font-size: 12px;
						color: rgba(45, 228, 248, 1.0);
						height: 26px;
						text-align: center;
						font-size: 12px;
						line-height: 24px;
						border-width: 1px;
						border-style: solid;
						border-color: rgba(45, 228, 248, 1.0);
						background-color: #e9eedf;

						.top_lei {
							margin: 2px 12px;
							height: 28px;
							white-space: nowrap;
						}

					}

					.item_middle_box {
					
						height: 20px;
						display: flex;
						align-items: center;
						justify-content: space-between;

						.item_middle_item {
							width: 60px;
							height: 20px;
							display: flex;
							align-items: center;

							image {
								width: 20px;
								height: 20px;
								margin-right: 10px;
							}

							text {
								font-size: 12px
							}
						}
					}

					.item-bottom {
						width: 200px;
						height: 20px;
						font-size: 14px;
					}
				}
			}
		}
	}
</style>
